#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
"""
@author:apple
@file:demo04.py
@time:2022/03/11
"""

import json
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

#caps = DesiredCapabilities.CHROME
#caps['loggingPrefs'] = {'performance': 'ALL'}
# 78版本的chrome需要加这个，https://stackoverflow.com/questions/56812190/protractor-log-type-performance-not-found-error
caps = {
    'browserName': 'chrome',
    'loggingPrefs': {
        'browser': 'ALL',
        'driver': 'ALL'
    },
    'goog:chromeOptions': {
        'perfLoggingPrefs': {
            'enableNetwork': True,
        },
        'w3c': False,
    },
}
driver = webdriver.Chrome(desired_capabilities=caps)
driver = webdriver.Chrome(desired_capabilities=caps)

driver.get('https://www.baidu.com')

driver.get_log("")
# logs = [json.loads(log['message'])['message'] for log in driver.get_log('performance')]
#
# with open('devtools.json', 'wb') as f:
#     json.dump(logs, f)

driver.close()

if __name__ == '__main__':
    pass
